<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<%@ include file="/pub/tree_common.jsp"%>
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
</HEAD>
<BODY topmargin="0" leftmargin="0">
<table  height="100%" width="100%">
   <tr>
    <td valign="top">
    <div style="float:right;margin-top: 5px;" >
     	<input type="button" onclick="addproductGroup();" class="button_nbw" value="添加" />
		<input type="button" onclick="modifyproductGroup();" class="button_nbw" value="修改" />
		<input type="button" onclick="delproductGroup()" class="button_nbw" value="删除" />
	</div>
    <div><a style="clear: both;line-height: 30px" href="javascript:window.location.reload()">刷新</a></div>
    <div id="treeObject" ></div>
    </td>
   </tr>
</table> 
<script>   
    tree=new dhtmlXTreeObject('treeObject',"100%","90%",0); 
    tree.setOnClickHandler(doOnClick); 
    tree.setImagePath("<%=xtreePath%>"); 
    tree.enableDragAndDrop(false);   
    tree.setXMLAutoLoading("<%=path%>/ext/productgroup/showTree");
    tree.loadXML("<%=path%>/ext/productgroup/showTree");
    function doOnClick(nodeId){
		if(nodeId != null){
			parent.rightFrame.location='<%=path%>/ext/products/get/productsList?groupId='+nodeId;
		}
	}
	function refreshItem(nodeId){
		tree.refreshItem(nodeId);
		tree.focusItem(nodeId);
	}
	function deleteItem(nodeId){
		tree.deleteItem(nodeId);
	}
	//增加分类树
	function addproductGroup(){
		var selectPid = tree.getSelectedItemId();
		if(selectPid == ""){
			top.alertMsg("请选择要增加产品分类的上级分类～");
		}else{
		    opendailog("{src:'<%=path %>/ext/productgroup/toForm/0?pid="+selectPid+"',title:'产品分组',width:600,height:300,savefunc:'savefunc'}",window);
		}
	}
	//编辑分类树
	function modifyproductGroup(){
		var selectId = tree.getSelectedItemId();
		if(selectId=="ROOT"){
			top.alertMsg("顶层产品分类不允许修改～");
		}else if(selectId == ""){
			top.alertMsg("请选择要修改的产品分类～");
		}else{
		    opendailog("{src:'<%=path %>/ext/productgroup/toForm/"+selectId+"',title:'产品分组',width:600,height:300,savefunc:'savefunc'}",window);
		}
	}
	
	//删除
	var delproductGroup = function(){
		var selectPid = tree.getSelectedItemId();
		if(selectPid=="ROOT"){
			top.alertMsg("顶层产品分类不允许删除～");
		}else if(selectPid == ""){
			top.alertMsg("请选择要增加产品分类的上级分类～");
		}else if(selectPid == "ROOT"){
			top.alertMsg("跟目录不能删除");
		}else{
			$.ajax({       
			   type: "POST",                
			   url: "<%=path %>/ext/productgroup/delproductgroup/"+selectPid,                    
			   success: function(msg){   
			  	 tree.deleteItem(selectPid);    
			     top.alertMsg("数据删除成功");   
			   }    
			}); 
		}
  
	}


	function savefunc(frame){
		var retv = frame.contentWindow.save()
		if(retv!="failure"){
			top.alertMsg("保存成功！");
			window.location.reload();
			return "success";
		}
		return retv;
	}
	
</script>
</body>
</html>
